﻿package mortal.game.view.treasureMap
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.mvc.core.*;

    public class TreasureMapCopyRightWin extends CopyInfoPanelBase
    {
        private var _smallMap:SmallMapEmbedView;
        private var _bgImg:GImageBitmap;
        private var _goldIcon:GBitmap;
        private var _coinIcon:GBitmap;
        private var _gold:GTextFiled;
        private var _coin:GTextFiled;
        private var _autoFightBtn:GLoadingButton;
        private var _leaveCopyBtn:GLoadingButton;
        private static var _instance:TreasureMapCopyRightWin;

        public function TreasureMapCopyRightWin(param1:String = "", param2:int = 250, param3:int = 380, param4:int = 6)
        {
            super(ImagesConst.copyInfoPanelTitle_treasureMap, 262, 461, 10);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bgImg = UIFactory.gImageBitmap(ImagesConst.TreasureMapCopyRightWinBg, 1, -3, _bodySprite);
            this._smallMap = UIFactory.smallMapEmbedView(ImagesConst.TreasureCopySmallMap, 15, 40, _bodySprite, true);
            this._smallMap.run();
            this._goldIcon = UIFactory.gBitmap("", 93, 324, this);
            this._goldIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitGoldBind));
            this._coinIcon = UIFactory.gBitmap("", 93, 350, this);
            this._coinIcon.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(EPriceUnit._EPriceUnitCoinBind));
            this._gold = UIFactory.textField("0", 116, 324, 100, 20, this);
            this._coin = UIFactory.textField("0", 116, 350, 100, 20, this);
            this._autoFightBtn = UIFactory.gLoadingButton(ResFileConst.autoFightBtn, 20, 390, 103, 38, _bodySprite);
            this._autoFightBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._leaveCopyBtn = UIFactory.gLoadingButton(ResFileConst.leaveCopyBtn, 140, 390, 103, 38, _bodySprite);
            this._leaveCopyBtn.configEventListener(MouseEvent.CLICK, this.clickHandler);
            NetDispatcher.addCmdListener(ServerCommand.GodLuckGiftCollectUpdate, this.updateReward);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.GodLuckGiftCollectUpdate, this.updateReward);
            this._goldIcon.dispose(param1);
            this._goldIcon = null;
            this._coinIcon.dispose(param1);
            this._coinIcon = null;
            this._gold.dispose(param1);
            this._gold = null;
            this._coin.dispose(param1);
            this._coin = null;
            this._bgImg.dispose(param1);
            this._bgImg = null;
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._autoFightBtn.dispose(param1);
            this._autoFightBtn = null;
            this._leaveCopyBtn.dispose(param1);
            this._leaveCopyBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._leaveCopyBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            }
            else if (event.target == this._autoFightBtn)
            {
                AIManager.cancelAll();
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFight_A));
            }
            return;
        }// end function

        private function updateReward(param1:Object) : void
        {
            if (param1.type == "coin")
            {
                this._coin.text = int(this._coin.text) + param1.value + "";
            }
            else if (param1.type == "gold")
            {
                this._gold.text = int(this._gold.text) + param1.value + "";
            }
            return;
        }// end function

        public static function get instance() : TreasureMapCopyRightWin
        {
            if (_instance == null)
            {
                _instance = new TreasureMapCopyRightWin;
            }
            return _instance;
        }// end function

        public static function get isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
